<%@ page language="java"  pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ include file="/includes/main.jsp"%>

<script type="text/javascript">

var basePrice = ${trip.discountPrice};
var partnerPrice = ${trip.partnerPrice};
var partnerGroupPrice = ${trip.partnerGroupPrice};
var customerPrice = ${trip.customerPrice};
var customerGroupPrice = ${trip.customerGroupPrice};
var partnerGroupNumber = ${trip.partnerGroupNumber};
var customerGroupNumber = ${trip.customerGroupNumber};

function countSpecialPrice() {
	
	var number = $('#number').val();
	countPrice();
	
	for(var i=0; i<number; i++) {
		var $select = $('#passengerSpecialPrice_'+i);
		if($select.val() != '') {
			var totalAmount = $('#amount').val();
			var specialPrice = parseFloat($select.find("option:selected").text().split(',')[1]);
			totalAmount = totalAmount - basePrice + specialPrice;
			$('#amount').val(totalAmount);
		}
	}
	
}

function countPrice() {
	
	var number = $('#number').val();
	
	if(number >= partnerGroupNumber)
		basePrice = partnerGroupPrice;
	else
		basePrice = partnerPrice;
	$('#amount').val(number * basePrice);

}

function generatePassengerHTML() {
	
	var number = $('#number').val();
	var $table = $('#passengerTable');
	var $tbody = $table.find("tbody");
	var tbodyHTML = "";
	$tbody.html(tbodyHTML);
	for(var i=0; i<number; i++) {
		tbodyHTML += '<tr>';
		tbodyHTML += '<td><input type="text" maxlength="10" size="10" name="tripOrder.passengers['+i+'].name" class="required textInput valid"></td>';
		tbodyHTML += '<td><input type="text" maxlength="" size="20" name="tripOrder.passengers['+i+'].id_card" class="required integer textInput"></td>';
		tbodyHTML += '<td>';
		tbodyHTML += '<select name="tripOrder.passengers['+i+'].type">';
		tbodyHTML += '<option value="400700">成人(男)</option>';
		tbodyHTML += '<option value="400701">成人(女)</option>';
		tbodyHTML += '<option value="400702">儿童</option';
		tbodyHTML += '</select>';
		tbodyHTML += '</td>';
		tbodyHTML += '<td><hi:entitySelect name="tripOrder.passengers['+i+'].specialPrice.id" id="passengerSpecialPrice_'+i+'"  filterName="specialPriceFilter" onchange="javascript:countSpecialPrice()" entityName="org.hi.trip.model.SpecialPrice" key="id" title="name,price" pattern="," /></td>';
		tbodyHTML += '</tr>';
	}
	$tbody.html(tbodyHTML);
	
	for(var i=0; i<number; i++) {
		$('#passengerSpecialPrice_'+i).prepend("<option value='' selected>无</option>");
	}
	
}
</script>
<h2 class="contentTitle"><hi:text key="新订单" parameterLanguageKeys=""/></h2>
<form action="tripOrderSave.action?navTabId=tripOrderList&callbackType=closeCurrent&ajax=1" method="post" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone)">
<div class="pageContent">
	<div class="pageFormContent" layoutH="97">
		<dl>
			<dt><hi:text key="开班日期" />：</dt><dd>${trip.trip_date}</dd>
			<input type="hidden" name="tripOrder.trip.id" value="${trip.id}"/>
			<input type="hidden" name="tripOrder.order_status" value="${orderStatus}" />
			<input type="hidden" name="tripOrder.order_type" value="${orderType}" />
		</dl>
		<dl>
			<dt><hi:text key="线路名称" />：</dt><dd>${trip.trip_model.trip_name}</dd>
		</dl>
		<dl>
			<dt><hi:text key="预订人数" entity="TripOrder"/>：</dt><dd><input type="text" id="number" onblur="generatePassengerHTML();countPrice();" name="tripOrder.numberOfPassagers" class="textInput required integer" value="${tripOrder.numberOfPassagers}" alt="<hi:text key="请输入人数"/>"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="订单金额" entity="TripOrder"/>：</dt><dd><input type="text" id="amount" name="tripOrder.amount" class="textInput float" readonly="readonly" /></dd>
		</dl>
	
		<!-- 联系人信息开始 -->
		<div class="divider"></div>
		
		<dl>
			<dt><hi:text key="联系人" entity="TripOrder"/>：</dt><dd><input type="text" name="tripOrder.contact" class="textInput required" value="${tripOrder.contact}" maxlength="30"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="联系人证件号" entity="TripOrder"/>：</dt><dd><input type="text" name="tripOrder.contactId" class="textInput required" value="${tripOrder.contactId}" maxlength="30"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="联系人手机" entity="TripOrder"/>：</dt><dd><input type="text" name="tripOrder.contactCellPhone" class="textInput required mobile" value="${tripOrder.contactCellPhone}" maxlength="30"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="联系人电话" entity="TripOrder"/>：</dt><dd><input type="text" name="tripOrder.contanctPhone" class="textInput phone" value="${tripOrder.contanctPhone}" maxlength="30"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="联系人邮箱" entity="TripOrder"/>：</dt><dd><input type="text" name="tripOrder.contactEmail" class="textInput email" value="${tripOrder.contactEmail}" maxlength="30"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="联系人邮编" entity="TripOrder"/>：</dt><dd><input type="text" name="tripOrder.contactPostCode" class="textInput integer" value="${tripOrder.contactPostCode}" alt="<hi:text key="请输入邮编"/>"/></dd>
		</dl>
		<dl>
			<dt><hi:text key="联系人地址" entity="TripOrder"/>：</dt><dd><input type="text" size="84" name="tripOrder.contactAddress" class="textInput" value="${tripOrder.contactAddress}" maxlength="80"/></dd>
		</dl>
		
		<div class="divider"></div>
		<!-- 联系人信息结束 -->
		
		<!-- 旅客名单开始 -->
		<div class="tabs">
			<div class="tabsHeader">
				<div class="tabsHeaderContent">
					<ul>
						<li><a href="javascript:void(0)"><span><hi:text key="旅客"/></span></a></li>
					</ul>
				</div>
			</div>
			<div class="tabsContent" style="height:150px;">
				<div>
					<table id="passengerTable" class="list nowrap" width="100%" >
						<thead>
							<tr>
								<th class=" required" name="name" size="6" maxlength="10"><hi:text key="旅客姓名" entity="Passenger"/></th>
								<th class=" required integer" name="id_card" size="10"><hi:text key="证件号" entity="Passenger"/></th>
								<th name="type" enumName="passengerType" size="10"><hi:text key="旅客类型" entity="Passenger"/></th>
								<th size="12">
								<hi:text key="特殊价格" entity="Passenger"/>
								</th>

							</tr>
						</thead>
						<tbody>

						</tbody>
					</table>
				</div>								
				
			</div>
			<div class="tabsFooter">
				<div class="tabsFooterContent"></div>
			</div>
		</div>				
	</div>
	<div class="formBar">
		<ul>
			<li><div class="buttonActive"><div class="buttonContent"><button type="submit"><hi:text key="保存"/></button></div></div></li>
			<li><div class="button"><div class="buttonContent"><button class="close" type="button"><hi:text key="关闭"/></button></div></div></li>
		</ul>
	</div>  
</div>
</form>

